package com.noble.glamour.module.local.chat.utils;

import android.os.Bundle;

import com.noble.glamour.R;
import com.noble.glamour.bean.db.msg.FLetter;
import com.noble.glamour.bean.db.msg.FMessage;
import com.noble.glamour.module.local.chat.msgtype.BaseMessageType;
import com.noble.glamour.module.local.chat.msgtype.bean.BaseMessage;
import com.noble.glamour.module.local.chat.msgtype.type.CommonMessage;
import com.noble.glamour.module.local.chat.msgtype.type.GiftMessage;
import com.noble.glamour.module.local.chat.msgtype.type.InviteVideoMessage;
import com.noble.glamour.module.local.chat.msgtype.type.SysNoticeMessage;
import com.noble.glamour.module.local.chat.msgtype.type.TextMessage;
import com.noble.glamour.module.local.chat.msgtype.type.VideoMessage;
import com.noble.glamour.module.logic.application.App;
import com.noble.library.utils.ScreenUtils;

/**
 * 消息处理工具类
 */
public class MsgUtils {
    private static int WIDTH_DEFAULT = -1;//默认
    private static int WIDTH_ZERO = 0;

    /**
     * 各种消息在聊天界面显示时的边距默认是80
     */
    public static int getDisplayWidth() {
        if (WIDTH_DEFAULT == -1) {
            WIDTH_DEFAULT = ScreenUtils.px2dp(App.context, App.getActivity().getResources().getDimension(R.dimen.px158_dp));
        }
        return WIDTH_DEFAULT;
    }

    public static int getDisplayWidthZero() {
        return WIDTH_ZERO;
    }

    /**
     * 私聊列表
     */
    public static BaseMessage parseToLetterMessage(Bundle bundle) {
        BaseMessage message = new BaseMessage();
        if (bundle == null) {
            return message;
        }
        BaseMessageType messageType = BaseMessageType.valueOf(bundle.getInt(FLetter.COLUMN_TYPE));
        if (messageType == null) {
            message = new BaseMessage(bundle, true);
            return message;
        }
        switch (messageType) {
            case html:
            case hint:
            case htmlText:
            case autoUpdateHtml:
                message = new TextMessage(bundle, true);
                break;
            case hi:
            case common:
                message = new CommonMessage(bundle, true);
                break;
            case gift:
            case wantGift:
                message = new GiftMessage(bundle, true);
                break;
            case video:
                message = new VideoMessage(bundle, true);
                break;
            case sysNotice:
                message = new SysNoticeMessage(bundle, true);
                break;
            case inviteVideoMass:
                message = new InviteVideoMessage(bundle, true);
                break;
            default:
                message = new BaseMessage(bundle, true);
                break;
        }
        return message;
    }


    /**
     * 根据消息类型，获取对应消息对象
     */
    public static BaseMessage parseToBaseMessage(Bundle bundle) {
        BaseMessage message = new BaseMessage();
        if (bundle == null) {
            return message;
        }

        BaseMessageType messageType = BaseMessageType.valueOf(bundle.getInt(FMessage.COLUMN_TYPE));
        if (messageType == null) {
            message = new BaseMessage(bundle);
            return message;
        }
        switch (messageType) {
            case html:
            case hint:
            case htmlText:
            case autoUpdateHtml:
                message = new TextMessage(bundle);
                break;
            case hi:
            case common:
                message = new CommonMessage(bundle);
                break;
            case gift:
            case wantGift:
                message = new GiftMessage(bundle);
                break;
            case video:
                message = new VideoMessage(bundle);
                break;
            case sysNotice:
                message = new SysNoticeMessage(bundle);
                break;
            case inviteVideoMass:
                message = new InviteVideoMessage(bundle);
                break;
            default:
                message = new BaseMessage(bundle);
                break;
        }
        return message;
    }
}
